
import axios from "axios"
import qs from "qs"
axios.defaults.baseURL = "http://localhost:8000"
let reget = axios.create({})
export default function httped({ method, url, data, header }) {
    if (method.toLowerCase() == "get") {
        if (header == "form") {
           
            reget.defaults['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
            url = url + "?" + qs.stringify(data)
            console.log(header)
        }
        else {
            url = url + "?" + qs.stringify(data)
        }
     }
    if (method.toLowerCase() == "post") {
        if (header == "form") {
            reget.defaults['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
            data = qs.stringify(data)
        } 
         else {
               data = qs.stringify(data)
         }
    }
    return new Promise((resolve,reject) => {
        reget({
            method,
            url,
            data
        }).then(res=>{
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
    
}